package <render>packageName</render>;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
<block v-repeat="item in imports">import <render>item</render>;
</block>

@Component
public class <render>className</render> extends BoRepository {

    @Autowired
    private QuoteCenter quoteCenter;

    @Autowired
    private <render>name</render>Dao dao;

    <block v-repeat="quote in quotes">
    @Autowired
    private <render>quote.type.name</render>Repository <render>quote.name</render>Repository;
    void query<render>quote.hName</render>(<render>name</render> bo) {
        <render>quote.type.name</render> qbo = <render>quote.name</render>Repository.createBo();
        if (qbo.queryByHolder(bo,"<render>quote.name</render>")) {
			if (bo.vo == null) {
				bo.createVo();
				bo.vo.set<render>quote.hName</render>(qbo.getVo());
			}
			bo._quote_<render>quote.name</render> = qbo;
		}
	}
    </block>

    public <render>name</render> createBo() {
        return new <render>name</render>(this);
    }

    boolean attach(Bo that, Bo target, String name) {
        return quoteCenter.attach(that, target, name);
    }

    void detach(Bo that, Bo target, String name) {
        quoteCenter.detach(that, target, name);
    }

    public <render>name</render> getBo(String id) {
        <render>name</render> bo = new <render>name</render>(this);
        bo.setId(id);
        if (bo.query()) {
            return bo;
        } else {
            return null;
        }
    }

    //保存操作
    @Transactional
    void save(<render>name</render> bo) {
        if (bo.vo != null) {
            <render>name</render>Be be = bo.vo.getBe();
            if (be != null) {
                if (bo.getId() == null) {
                    bo.setId(UUID.randomUUID().toString());
                    be.setId(bo.getId());
                }
                dao.save(be);
            }
        }
    }

    //删除操作
    @Transactional
    void delete(<render>name</render> bo) {
        if (bo.vo != null) {
            <render>name</render>Be be = bo.vo.getBe();
            if (be != null) {
                dao.delete(be);
            }
        }
    }


    boolean querySelf(<render>name</render> bo, Expression exp) {
        <render>name</render>Be be = (<render>name</render>Be) nativeQueryHelper.querySelf(bo, exp);
        if (be == null) {
            return false;
        }
        bo.setId(be.getId());
        bo.createVo();
        bo.getVo().setBe(be);
        return true;
    }

    //查询操作
    boolean queryById(<render>name</render> bo) {
        if (bo.getId() == null) {
            return false;
        }
        Optional<<render>name</render>Be> one = dao.findById(bo.getId());
        if (!one.isPresent()) {
            return false;
        }
        <render>name</render>Vo vo = new <render>name</render>Vo();
        vo.setBe(one.get());
        bo.vo = vo;
        return true;
    }

    boolean queryByHolder(Bo holder, <render>name</render> bo,String selfName) {
        <render>name</render>Be be = (<render>name</render>Be) nativeQueryHelper.queryByHolder(holder, bo,selfName);
        if (be == null) {
            return false;
        }
        bo.setId(be.getId());
        bo.createVo();
        <render>name</render>Vo vo = bo.getVo();
        vo.setBe(be);
        return true;
    }


}
